package com.example.water.controller;

import com.example.water.pojo.RespBean;
import com.example.water.pojo.StSitinfoB;
import com.example.water.pojoDTO.StSitinfoBDTO;
import com.example.water.service.StSoilRService;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author Shunrai
 * @create 2023/11/9 22:14
 * @Version 1.0
 * @Description
 */
@Tag(name = "实时雨情")
@RestController
@RequestMapping("/StSoilR")
@ApiResponse(responseCode = "404", description = "查询失败")
@ApiResponse(responseCode = "200", description = "查询成功")
public class StSoilRController {
    @Autowired
    private StSoilRService stSoilRService;

    @Operation(summary = "分页获取雨量信息")
    @ApiResponse(responseCode = "404", description = "查询失败")
    @ApiResponse(responseCode = "200", description = "查询成功")
    @GetMapping("/page")
    public RespBean<StSitinfoBDTO> getSoilPage(@RequestParam(defaultValue = "7" ,required = false)Integer pageSize,
                                                 @RequestParam(defaultValue = "1",required = false)Integer currentPage){
        List<StSitinfoB> rPage = stSoilRService.getStSoilRPage(pageSize, currentPage);
        Integer count =stSoilRService.getAllCount();
        StSitinfoBDTO stSitinfoBDTO = new StSitinfoBDTO(rPage,count);
        return RespBean.success("查询成功",stSitinfoBDTO);
    }

    @Operation(summary = "各市最大雨量")
    @GetMapping("/getMax")
    public RespBean<StSitinfoBDTO> getMaxSoilByCity(@RequestParam(defaultValue = "7" ,required = false)Integer pageSize,
                                                    @RequestParam(defaultValue = "1",required = false)Integer currentPage){
        List<StSitinfoB> maxSoil = stSoilRService.getMaxSoil(pageSize, currentPage);
        Integer count= stSoilRService.getMaxAllCount();
        StSitinfoBDTO stSitinfoBDTO = new StSitinfoBDTO(maxSoil,count);
        return RespBean.success("查询成功",stSitinfoBDTO);

    }

    @Operation(summary = "获取所有雨量数据")
    @GetMapping("/getAll")
    public RespBean<StSitinfoBDTO> getAllRiver() {
        Integer count = stSoilRService.getAllCount();
        long counted = stSoilRService.count();
        List<StSitinfoB> rPage = stSoilRService.getStSoilRPage((int) counted, 1);
        StSitinfoBDTO stSitinfoBDTO = new StSitinfoBDTO(rPage, count);
        return RespBean.success("查询成功", stSitinfoBDTO);
    }
}
